<template xmlns:el-col="http://www.w3.org/1999/html">
    <div>
        <el-dialog
                width="400px"
                :visible.sync="deleteshow"
                :modal="false"
        >
            <p>确认删除知识库吗？</p>
            <el-button style="width: 40%" @click="deleterepository" type="success" plain>确认</el-button>
            <el-button style="width:40%;float: right" @click="deleteshow=false" type="primary" plain>取消</el-button>
        </el-dialog>
        <div v-for="item in repositories" :key="id">

            <el-card class="box-card">
                <div @click="toRepository(item.collectbox_id)"><p class="context">
                    {{item.name}}
                </p>
                    <p>{{item.category}}</p></div>


                <el-button size="small" style="margin-top: 10px;margin-left: 50px"
                           @click.native="toRepositoryEdit(item.collectbox_id)">
                    编辑
                </el-button>
                <el-button size="small" style="margin-top: 10px;margin-left: 50px"
                           @click="changedelete(item.collectbox_id)">删除
                </el-button>


            </el-card>
        </div>
    </div>

</template>

<script>


    import Cookies from "js-cookie";
    import POST from "../../api/POST";

    export default {
        name: "self-repositories",
        components: {},
        data() {
            return {
                id: '',
                repositories: '',
                deleteshow: false,
                deleteid: '',
                circleUrl: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
            }
        },
        methods: {
            deleterepository() {
                let data = {'id': this.id, 'collectbox_id': this.deleteid};
                POST.deleteCollectbox(data).then(res => {

                });
                this.deleteshow = false;
                this.$router.push({path: '/personal/home'});
            }, toRepository(cid) {
                this.$router.push({path: '/repository/' + cid + '/self-repository'});
            }, toRepositoryEdit(cid) {
                this.$router.push({path: '/repository/' + cid + '/repositoryedit'});
            }, changedelete(cid) {
                this.deleteid = cid;
                this.deleteshow = true;
            }

        }, mounted() {
            this.info = Cookies.get('info');
            this.info = JSON.parse(this.info);
            this.id = this.info.account;
            console.log(this.id);
            let data = {'id': this.id};
            POST.showCollectbox(data).then(res => {
                this.repositories = res.content
            });
        }
    }
</script>

<style scoped>
    .box-card {
        margin-top: 20px;

        width: 150px;
        height: 150px;
    }
</style>